package fr.afcepf.ai89.esharing.data;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import fr.afcepf.ai89.esharing.entity.Emprunt;
import fr.afcepf.ai89.esharing.entity.LibelleSousAvis;

@Stateless
public class DAOLibelleSousAvis implements IDAOLibelleSousAvis {

	@PersistenceContext(unitName = "ESharingPhase22")
	EntityManager em;

	@Override
	public LibelleSousAvis getLibelleSA(int idLibelleSA) {
		
		Query hql = em.createQuery("SELECT lsa FROM LibelleSousAvis lsa WHERE lsa.idLibelleSousAvis = :param");

		hql.setParameter("pmp", idLibelleSA);
		LibelleSousAvis lsa = (LibelleSousAvis)hql.getSingleResult();
		
		return lsa;

	}

	@Override
	public List<LibelleSousAvis> getLibellesSA() {
		
		Query hql = em.createQuery("SELECT lsa FROM LibelleSousAvis lsa");

		List<LibelleSousAvis> listeLsa = (List<LibelleSousAvis>)hql.getResultList();
		
		return listeLsa;

	}

	@Override
	public int addLibelleSA(LibelleSousAvis libelleSA) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int majLibelleSA(LibelleSousAvis libelleSA) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<LibelleSousAvis> getLibellesSAsurEmprunteur() {
		
		Query hql = em.createQuery("SELECT lsa FROM LibelleSousAvis lsa WHERE lsa.surEmprunteur = 1");

		List<LibelleSousAvis> listeLsa = (List<LibelleSousAvis>)hql.getResultList();
		
		return listeLsa;

	}

	@Override
	public List<LibelleSousAvis> getLibellesSAsurPreteur() {
		
		Query hql = em.createQuery("SELECT lsa FROM LibelleSousAvis lsa WHERE lsa.surPreteur = 1");

		List<LibelleSousAvis> listeLsa = (List<LibelleSousAvis>)hql.getResultList();
		
		return listeLsa;

	}

}
